/**
 * @class Ext.app.DanhSachPhieuNhapKhoPanel
 * @extends Ext.panel.Panel
 */
Ext.define('Ext.app.DanhSachPhieuNhapKhoPanel', {
    extend: 'Ext.panel.Panel',
    alias: 'widget.danhSachPhieuNhapKhoPanel',
    autoScroll: true,
    border: true,
    layout: 'border',
    titleAlign: 'center',
    items: [
        {
            region: 'center',
            xtype: 'gridpanel',
            columnLines: true,
            store: {
                fields: ['impProdPK', 'date', 'soPhieu', 'tuKho', 'denKho', 'dienGiai'],
                pageSize: 25,
                proxy: {
                    type: 'ajax',
                    url: 'DanhSachPhieuNhapKho.jsp',
                    reader: {
                        type: 'json',
                        root: 'root',
                        totalProperty: 'totalCount'
                    }
                }
            },
            columns: [{ 
                sortable: false,
                draggable: false,
                menuDisabled: true,
                width: 30,
                align: 'center',
                resizable: false,
                renderer: Ext.renderPopupIcon
            },{
                text: this.translations.get("HOME.NGAY_NHAP"),
                sortable: false,
                draggable: false,
                menuDisabled: true,
                dataIndex: 'date',
                width: 80
            },{
                text: this.translations.get("HOME.SO_PHIEU"),
                sortable: false,
                draggable: false,
                menuDisabled: true,
                dataIndex: 'soPhieu',
                width: 80
            },{
                text: this.translations.get("HOME.TU_KHO"),
                sortable: false,
                draggable: false,
                menuDisabled: true,
                dataIndex: 'tuKho',
                width: 300
            },{
                text: this.translations.get("HOME.DEN_KHO"),
                sortable: false,
                draggable: false,
                menuDisabled: true,
                dataIndex: 'denKho',
                width: 150
            },{
                text: this.translations.get("HOME.DIEN_GIAI"),
                sortable: false,
                draggable: false,
                menuDisabled: true,
                dataIndex: 'dienGiai',
                flex: 1
            }],
            viewConfig: {
                loadingText: this.translations.get("HOME.PLEASE_WAIT"),
                stripeRows: true
            },
            listeners: {
                cellclick: function(grid, td, cellIndex, record, tr, rowIndex, e, eOpts) {
                    if(cellIndex == 0 && td.innerHTML.indexOf("popupmenu") != -1) {
                        var impProdPK = record.get("impProdPK");
                        var items = [
                            {text: translations.get("HOME.XEM_CHI_TIET"), handler: function() { xemPhieuNhapKhoPanel(impProdPK); }, icon:"images/viewitem.gif"}
                        ];
                        openPopupMenu(e, items);
                    }
                }
            },
            afterFirstLayout: function() {
                // paging bar on the bottom [
                var bbar = Ext.create('Ext.PagingToolbar', {
                    store: this.getStore(),
                    beforePageText: 'Trang',
                    afterPageText: '/ {0}'
                });
                bbar.dock = "bottom";
                this.addDocked(bbar);
                //]
                this.getStore().load();
            }
        },
    ]
});
